package com.asia5b.a5mall.middleware.model.shop

import androidx.databinding.ObservableBoolean
import com.asia5b.a5bmall.resource.ResString
import com.asia5b.a5mall.middleware.R
import com.asia5b.a5mall.middleware.model.base.BaseModel
import com.asia5b.a5mall.middleware.model.bean.CartMultiItemEntity
import com.asia5b.a5mall.middleware.model.member.UserCouponModel
import com.asia5b.a5mall.middleware.utils.WTimeUtils
import com.google.gson.annotations.SerializedName

/**
 * Created by zhangyuncai on 2020/5/9.
 */
open class AbsShopModel : BaseModel(), CartMultiItemEntity {
    var type = CartMultiItemEntity.CartShopItem

    /*--------店铺辅助字段------------*/
    var absSHopCreateTimeText = ""
        get() {
            return WTimeUtils.format("${absShopCreatetime * 1000}", WTimeUtils.text_yyyy_MM_dd)
        }
    var absShopGoodsNumText = ""
        //店铺所有商品
        get() {
            return "$absShopGoodsNum"
        }
    var absShopCollectCntText = ""
        get() {
            return String.format(ResString.get(R.string.数_人关注), "${absShopCollectCnt}")
        }
    var absShopDetailAddressText = ""
        get() {
            val stringBuffer = StringBuffer()
            if (!absShopCountry.isEmpty()) {
                stringBuffer.append("${absShopCountry} ")
            }
            if (!absShopProvince.isEmpty()) {
                stringBuffer.append("${absShopProvince} ")
            }
            if (!absShopCity.isEmpty()) {
                stringBuffer.append("${absShopCity} ")
            }
            if (!absShopTown.isEmpty()) {
                stringBuffer.append("${absShopTown} ")
            }
            if (!absShopDetailAddress.isEmpty()) {
                stringBuffer.append("${absShopDetailAddress}")
            }
            return stringBuffer.toString()
        }

    /*身份认证*/
    var userCheck = ""
        get() {
            return ResString.get(R.string.已验证)
        }

    /*店铺认证*/
    var shopCheck = ""
        get() {
            return ResString.get(R.string.店铺_已验证)
        }
    var collectCnt = ""
        get() {
            return String.format(ResString.get(R.string.数_人关注), "${absShopCollectCnt}")
        }

    //另外创建的字段
    /**是否是自营店铺*/
    var isSelf = false
        get() {
            return absShopId == 1
        }

    /**是否选中*/
    var isCheck = false
        get() {
            return absShopChecked == 1
        }
    var checkedDeleteObservable = ObservableBoolean()

    var checkOB = ObservableBoolean(false)

    /*--------店铺辅助字段------------*/
    //店铺id
    @SerializedName(value = "absShopId", alternate = ["shop_id", "seller_id"])
    var absShopId = 0

    //店铺名称
    @SerializedName(value = "absShopName", alternate = ["shop_name", "seller_name"])
    var absShopName = ""


    //店铺logo
    @SerializedName(value = "absShopLogo", alternate = ["shop_logo", "logo"])
    var absShopLogo = ""


    //店铺背景图
    @SerializedName(value = "absShopBackImg", alternate = ["shop_banner"])
    var absShopBackImg = ""


    //店铺创店时间
    @SerializedName(value = "absShopCreatetime", alternate = ["shop_createtime"])
    var absShopCreatetime = 0L

    //店铺内商品数量
    @SerializedName(value = "absShopGoodsNum", alternate = ["goods_num"])
    var absShopGoodsNum = 0

    //店铺内商品
    @SerializedName(value = "absShopGoodsList", alternate = ["goods_list", "sku_list"])
    var absShopGoodsList: ArrayList<AbsGoodsModel>? = null

    //关注店铺数量
    @SerializedName(value = "absShopCollectCnt", alternate = ["shop_collect"])
    var absShopCollectCnt = 0

    //店铺说明
    @SerializedName(value = "absShopIntro", alternate = ["description", "shop_desc"])
    var absShopIntro = ""


    //店铺总评分
    @SerializedName(value = "absShopCredit", alternate = ["credit", "shop_praise_rate"])
    var absShopCredit = 0.0
    var absShopCreditText = ""
        get() {
            return "${absShopCredit}"
        }
    var absShopCreditFloat=0f
    get() {return absShopCredit.toFloat()}

    //物流评分
    @SerializedName(value = "absShopDeliveryCredit", alternate = ["shop_delivery_credit"])
    var absShopDeliveryCredit = 0.0

    //描述评分
    @SerializedName(value = "absShopDescCredit", alternate = ["shop_description_credit"])
    var absShopDescCredit = 0.0

    //服务态度
    @SerializedName(value = "absShopServiceCredit", alternate = ["shop_service_credit"])
    var absShopServiceCredit = 0.0

    //联系电话
    @SerializedName(value = "absShopLinkPhone", alternate = ["link_phone"])
    var absShopLinkPhone = ""


    //商品所在国家
    @SerializedName(value = "absShopCountry", alternate = ["shop_province"])
    var absShopCountry = ""


    //商品所在州
    @SerializedName(value = "absShopProvince", alternate = ["shop_city"])
    var absShopProvince = ""


    //商品所在城市
    @SerializedName(value = "absShopCity", alternate = ["shop_county"])
    var absShopCity = ""


    //商品所在城镇
    @SerializedName(value = "absShopTown", alternate = ["shop_town"])
    var absShopTown = ""


    //商品所在详细地址
    @SerializedName(value = "absShopDetailAddress", alternate = ["shop_add"])
    var absShopDetailAddress = ""


    //在购物车中,店铺是否被选中
    @SerializedName(value = "absShopChecked", alternate = ["checked"])
    var absShopChecked = 0

    //店铺内优惠券
    @SerializedName(value = "absShopCouponList", alternate = ["coupon_list"])
    var absShopCouponList: ArrayList<UserCouponModel>? = null
    override val itemType: Int
        get() = type


}


data class ShopCollectModel(
        //是否已关注店铺
        var message: Boolean = false) : BaseModel()

/*
{
"message": false
}
 */